package net.bblot.lottery.push.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.igexin.sdk.PushConsts;

import net.bblot.lottery.push.PushUtil;
import net.bblot.lottery.util.Logger;

public class PushReceiver extends BroadcastReceiver {
	public PushReceiver() {
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		Bundle bundle = intent.getExtras();
		Logger.d("PushReceiver", 18 + "");
		switch (bundle.getInt(PushConsts.CMD_ACTION)) {
		case PushConsts.GET_CLIENTID:
			String cid = bundle.getString("clientid");
			PushUtil.saveClintId(context, cid);
			Logger.d("PushReceiver", "clientid==" + cid);
			// TODO:处理cid返回
			break;
		case PushConsts.GET_MSG_DATA:

			String taskid = bundle.getString("taskid");
			String messageid = bundle.getString("messageid");
			byte[] payload = bundle.getByteArray("payload");
			if (payload != null) {
				String data = new String(payload);
				// TODO:接收处理透传（payload）数据
				Logger.d("PushReceiver", data);
				PushUtil.processData(data, context);
			}
			break;
		default:
			break;
		}

	}
}
